package com.lzw.kotdemo


import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View

import com.lzw.kotdemo.adapter.ForecastListAdapter

import com.lzw.kotdemo.bean.RequestForecastCommand
import kotlinx.android.synthetic.main.second.*

import org.jetbrains.anko.*



class MainActivity : AppCompatActivity() {

    private val items = listOf(
            "Mon 6/23 - Sunny - 31/17",
            "Tue 6/24 - Foggy - 21/8",
            "Wed 6/25 - Cloudy - 22/17",
            "Thurs 6/26 - Rainy - 18/11",
            "Fri 6/27 - Foggy - 21/10",
            "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18",
            "Sun 6/29 - CONNET"
    )
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.second)
//        val forecastList: RecyclerView = find(R.id.forecast_list)
        forecast_list.layoutManager = LinearLayoutManager(this)




        doAsync {
            val result = RequestForecastCommand("94043").execute()
            uiThread {
                forecast_list.adapter = ForecastListAdapter(result){forecast -> toast(forecast.date) }
            }
        }
        /**
         * as you can see,to create an anonymous class ,we create an object that implements the
         * interface we created.Not very nice,right?That is because we are not making use of the
         * powers of functional programming ,but you'll learn how to convert this code into sth
         * much simpler in the next chapter
         */
    }



    inline fun supportsLollipop(code:() -> Unit){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            code()
        }
    }



    /**
     * SemiColons is not necessary
     * if the result is a single expression ,you can get rid of brackets and use
     */
    fun add(x:Int,y:Int) :Int = x + y

    fun minus(x:Int, y: Int) : Int{
        return y- x
    }

    var i:Int = 7
    var d:Double = i.toDouble()
    //There are no automatic conversions among numeric types,For Instance,you cannot assgin an
    //Int to Double variable.An explicit conversion must be done,using one of the many functions
    //available: hexadecimal 十六进制





}
